package com.mall.shopping.services;

import com.mall.shopping.ITestProductService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.TestProductConverter;
import com.mall.shopping.dal.entitys.Item;
import com.mall.shopping.dal.persistence.ItemMapper;
import com.mall.shopping.dto.TestProductDetaiDto;
import com.mall.shopping.dto.TestProductDetailRequest;
import com.mall.shopping.dto.TestProductDetailResponse;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class ITestProductServiceImpl implements ITestProductService {

    @Autowired
    ItemMapper itemMapper;

    @Autowired
    TestProductConverter testProductConverter;

    @Override
    public TestProductDetailResponse getProductDetail(TestProductDetailRequest request) {

        TestProductDetailResponse testProductDetailResponse = new TestProductDetailResponse();
        try {

            System.out.println("调用到了getProductDetail");
            // 执行参数校验
            request.requestCheck();

            Item item = itemMapper.selectByPrimaryKey(request.getProductId());
            TestProductDetaiDto testProductDetaiDto = testProductConverter.itemToProductDTO(item);
            testProductDetailResponse.setTestProductDetaiDto(testProductDetaiDto);
            testProductDetailResponse.setCode(ShoppingRetCode.SUCCESS.getCode());
            testProductDetailResponse.setMsg(ShoppingRetCode.SUCCESS.getMessage());
            return testProductDetailResponse;
        } catch (Exception e) {
            testProductDetailResponse.setCode(ShoppingRetCode.SYSTEM_ERROR.getCode());
            testProductDetailResponse.setMsg(ShoppingRetCode.SYSTEM_ERROR.getMessage());
        }

        return testProductDetailResponse;
    }
}
